home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1368 / 1368.xpi / chrome / clrtabs.jar / content / adv.js < prev    next >
Text File  |  2009-10-30  |  7KB  |  210 lines

  1. var cto = {
  2. advPrefInit:function()
  3.     {
  4.     cto.adv_toggle_state(document.getElementById('advenable').checked);    
  5.     },
  6.  
  7. saveDomains:function()
  8.     {
  9.     if(!document.getElementById("domainrows")) return;
  10.     var domains =  document.getElementById("domainrows").getElementsByAttribute("rel","domain");
  11.     var colors =  document.getElementById("domainrows").getElementsByAttribute("rel","color");
  12.     dpref= new Array;
  13.     var rawDomain,color;
  14.     for(i=0;i <domains.length ; i++)
  15.         {
  16.         rawDomain = domains[i].value
  17.             rawDomain = rawDomain.replace(/^\s+|\s+$/, '');
  18.         color = colors[i].value;
  19.             color = color.replace(/^\s+|\s+$/, '');
  20.         if(rawDomain == '') continue;
  21.         if(color == '') continue;
  22.         rawDomain.replace(/https:\/\//i,"")                 
  23.         rawDomain=rawDomain.replace(/http:\/\//i,"")                     
  24.         rawDomain.replace(/ftp:\/\//i,"")                     
  25.         rawDomain.replace(/\//i,"");
  26.                  
  27.         dpref.push(rawDomain+"~"+colors[i].value);
  28.         }
  29.         Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.clrtabs.").setCharPref("dpref",dpref.join("`"));
  30.     },
  31.  
  32. resetPref:function()
  33.     {
  34.     var ctPref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  35.     //    try because of http://developer.mozilla.org/en/docs/Preferences_System:preference
  36.     //    https://developer.mozilla.org/en/Preferences_System/preference>> methods throws exception if not a user value
  37.     try
  38.         {
  39.         //var cPref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBoolPref("extensions.clrtabs.advanced").reset();
  40.         try{ctPref.clearUserPref("extensions.clrtabs.advanced");}catch(e){};
  41.         
  42.         //try{document.getElementById('adv').reset();}catch(e){}
  43.         cto.adv_toggle_state(document.getElementById('adv').checked);
  44.         }
  45.     catch(e)
  46.         {
  47.         dump('\n\n\nerr:adv '+e);
  48.         }    
  49.     var scheme = ctPref.getIntPref("extensions.clrtabs.scheme")
  50.     if(scheme == 1)
  51.         {        
  52.         try{ctPref.clearUserPref("extensions.clrtabs.satmin");}catch(e){};
  53.         try{ctPref.clearUserPref("extensions.clrtabs.satmax");}catch(e){};
  54.         try{ctPref.clearUserPref("extensions.clrtabs.lummin");}catch(e){};
  55.         try{ctPref.clearUserPref("extensions.clrtabs.lummax");}catch(e){};
  56.                         /*try{document.getElementById('satmin').reset();}catch(e){}
  57.         try{document.getElementById('satmax').reset();}catch(e){}
  58.         try{document.getElementById('lummin').reset();}catch(e){}
  59.         try{document.getElementById('lummax').reset();}catch(e){}*/
  60.         }
  61.     if(scheme == 2)
  62.         {
  63.         try{ctPref.clearUserPref("extensions.clrtabs.sat");}catch(e){};
  64.         try{ctPref.clearUserPref("extensions.clrtabs.lum");}catch(e){};
  65.         /*
  66.         try{document.getElementById('sat').reset();}catch(e){}
  67.         try{document.getElementById('lum').reset();}catch(e){}
  68.         */
  69.         }
  70.     },
  71.  
  72. val:function(txtbox)
  73.     {
  74.     var test = txtbox.value
  75.     if(isNaN(parseInt(txtbox.value)) || 0  > test || test > 100 )
  76.         {
  77.         alert('Please provide a valid integer between 0 and 100.');
  78.         }
  79.     else
  80.         {
  81.         txtbox.value=parseInt(txtbox.value);
  82.         }
  83.     },
  84.  
  85. adv_toggle_state:function(state)
  86.     {
  87.     var scheme = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.scheme");
  88.     //document.getElementById('adv_group').style.visibility=!document.getElementById('advenable').checked;
  89.     //sizeToContent();
  90.     /*document.getElementById('adv_group').style.setProperty("visibility", 'collapse' ,'important');
  91.     document.getElementById('adv_group2').style.setProperty("visibility", 'collapse' ,'important');
  92.     */
  93.     /*
  94.     document.getElementById('adv_group').collapsed = true;
  95.     document.getElementById('adv_group2').collapsed = true;
  96.     */
  97.     if(scheme == 3)
  98.                 {
  99.                 document.getElementById('advenable').style.setProperty("visibility", 'collapse' ,'important');
  100.                 var altLabel = document.createElement('label');
  101.                 altLabel.setAttribute("value","No Advanced Preferences for On-Demand-Coloring");
  102.                 document.getElementById('advenable').parentNode.appendChild(altLabel);
  103.                 //document.getElementById('adv_group').collapsed = true;    
  104.                 }
  105.     else
  106.         {
  107.         document.getElementById('advenable').style.setProperty("visibility", 'visible' ,'important');
  108.         }
  109.     try
  110.         {
  111.         if(state)
  112.             {
  113.             if(scheme == 1)
  114.                 {
  115.                 document.getElementById('adv_group').style.setProperty("visibility", 'visible' ,'important');
  116.                 //document.getElementById('adv_group').collapsed = false;
  117.                 }
  118.             if(scheme == 2)
  119.                 {
  120.                 document.getElementById('adv_group2').style.setProperty("visibility", 'visible' ,'important');
  121.                 //document.getElementById('adv_group2').collapsed = false;
  122.                 }
  123.             //return true;
  124.             }
  125.         else
  126.             {            
  127.             if(scheme == 1)
  128.                 {
  129.                 document.getElementById('adv_group').style.setProperty("visibility", 'collapse' ,'important');
  130.                 //document.getElementById('adv_group').collapsed = true;    
  131.                 }
  132.             if(scheme == 2)
  133.                 {
  134.                 document.getElementById('adv_group2').style.setProperty("visibility", 'collapse' ,'important');
  135.                 //document.getElementById('adv_group2').collapsed = true;
  136.                 }
  137.             //resetPref();
  138.             //document.getElementById("clrAppPreferences").
  139.             }
  140.         sizeToContent();
  141.         }
  142.     catch(e){alert(e);}
  143.     return true;     
  144.     },
  145.  
  146. setSatLum:function()
  147.     {
  148.     // validation before saving
  149.     var scheme = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.scheme");
  150.     if(Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBoolPref("extensions.clrtabs.advanced") == true)
  151.         {
  152.         if(scheme==1)
  153.             {
  154.             var satmax=document.getElementById('satmax');
  155.             var satmin=document.getElementById('satmin');
  156.             var lummax=document.getElementById('lummax');
  157.             var lummin=document.getElementById('lummin');
  158.             if(satmin.value >= satmax.value  || lummin.value >= lummax.value ||  satmin.value > 100  || satmax.value > 100  || lummin.value > 100 || lummax.value > 100 )
  159.                 {
  160.                 alert("Maximum values should be greater than minimum values chosen.\nValues shouldn't be greated than 100.");
  161.                 return false;
  162.                 }
  163.             else
  164.                 {
  165.                 return true;
  166.                 }
  167.             }
  168.         if(scheme==2)
  169.             {
  170.             var sat=document.getElementById('sat');
  171.             var lum=document.getElementById('lum');
  172.             if(sat>100 || lum>100)
  173.                 {
  174.                 alert('Maximum values should not be greater than 100.');
  175.                 return false;
  176.                 }
  177.             }
  178.         }
  179.     else {return;}
  180.     
  181.     },
  182.  
  183. browsebgnd:function()
  184.     {
  185.     
  186.     const nsIFilePicker = Components.interfaces.nsIFilePicker;    
  187.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  188.     fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
  189.     fp.appendFilters(nsIFilePicker.filterImages);
  190.     
  191.     var rv = fp.show();
  192.     if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) 
  193.         {
  194.         var file = fp.file;
  195.         // Get the path as string. Note that you usually won't 
  196.         // need to work with the string paths.
  197.         //var path = fp.file.path;
  198.         var path = fp.fileURL.spec;
  199.         // work with returned nsILocalFile...    
  200.         document.getElementById('image-path').value=path;
  201.         document.getElementById("clrBgPicPath").value = path;
  202.         }
  203.     },
  204.  
  205. clrPrefPaneLoad:function(event)
  206.     {
  207.     document.getElementById('image-path').disabled=!(document.getElementById('clrTabBgnd').checked);
  208.     document.getElementById('browseBgnd').disabled=!(document.getElementById('clrTabBgnd').checked);
  209.     }
  210. }